﻿namespace QFlow.Utils
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using DevComponents.DotNetBar;

    /// <summary>
    /// represent the base class for all forms used in QFlow 
    /// </summary>
    public partial class BaseForm : DevComponents.DotNetBar.Office2007Form
    {
        /// <summary>
        /// private member holds an instance of the context or null
        /// </summary>
        private QFlow.Data.QFlowDbContext context;

        /// <summary>
        /// Initializes a new instance of the <see cref="BaseForm"/> class.
        /// </summary>
        public BaseForm()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="BaseForm"/> class.
        /// </summary>
        public BaseForm(QFlow.Data.QFlowDbContext context)
        {
            InitializeComponent();
            this.context = context;
        }

        /// <summary>
        /// Gets the context is exists or create now one and retuns it
        /// </summary>
        /// <value>The context.</value>
        [Browsable(false)]
        public QFlow.Data.QFlowDbContext Context
        {
            get
            {
                if (context == null)
                {
                    context = new QFlow.Data.QFlowDbContext();
                }

                return context;
            }
        }

        /// <summary>
        /// Clear the context.
        /// <remarks>
        /// when the context is used angain anaother one will be created
        /// </remarks>
        /// </summary>
        public void ResetContext()
        {
            context = null;
        }


        protected override void OnActivated(EventArgs e)
        {
            this.WindowState = FormWindowState.Maximized;
            base.OnActivated(e);
        }
    }
}
